package com.datn.DataAccess;

import java.util.ArrayList;
import java.util.List;

import com.datn.activity.R;
import com.datn.beans.FavouriteBean;
import com.datn.utils.PreferenceUtils;
import com.datn.utils.places.ItemPlaceViewGroup;
import com.datn.utils.places.ItemRecentViewGroup;
import com.datn.utils.places.Place;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListRecentAdapter extends ArrayAdapter<FavouriteBean>{

	private ArrayList<FavouriteBean> listRecentPlace;
	private int resourse;
	private Context mContext;
	
	public ListRecentAdapter(Context context, int textViewResourceId,
			ArrayList<FavouriteBean> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		mContext=context;
		listRecentPlace=objects;
		this.resourse=textViewResourceId;
		
	}
	
	
	@Override
	public FavouriteBean getItem(int position) {
		// TODO Auto-generated method stub
		return listRecentPlace.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	
	@Override
	public int getPosition(FavouriteBean item) {
		// TODO Auto-generated method stub
		return listRecentPlace.indexOf(item);
	}
	

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		 View workView = convertView;
	        
	        if (workView == null) {
	            workView = new ItemRecentViewGroup(getContext());
	        }
	        
	      
	        final FavouriteBean recentPlace = listRecentPlace.get(position);

	        if (recentPlace != null) {
	            ImageView tvImagePlace = ((ItemRecentViewGroup) workView).tvImagePlace;
	            TextView tvName = ((ItemRecentViewGroup) workView).tvName;
	            
	            /*try {
	            	tvImagePlace.setImageResource(PreferenceUtils.getResourceCategory());
	            	tvImagePlace.setImageDrawable(mContext.getResources().getDrawable(PreferenceUtils.getResourceCategory()));
	            	
	            	//Log.v("OK", String.valueOf(PreferenceUtils.getResourceCategory()));
				} catch (Exception e) {
					// TODO: handle exception
					Log.v("Warning", "Cannot set resource");
				}*/
	            
	            tvName.setText(recentPlace.getNameplace());
	    
	        }        
	        return workView;
	}


	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
	}
	
	
	

	
	
}
